<?php
define ('UTF32_BIG_ENDIAN_BOM'   , chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF));
define ('UTF32_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00));
define ('UTF16_BIG_ENDIAN_BOM'   , chr(0xFE) . chr(0xFF));
define ('UTF16_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE));
define ('UTF8_BOM'               , chr(0xEF) . chr(0xBB) . chr(0xBF));

class StringFuncs{
    
//    static const $UTF32_BIG_ENDIAN_BOM        = chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF);
//    static const $UTF32_LITTLE_ENDIAN_BOM    = chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00);
//    static const $UTF16_BIG_ENDIAN_BOM        = chr(0xFE) . chr(0xFF);
//    static const $UTF16_LITTLE_ENDIAN_BOM    = chr(0xFF) . chr(0xFE);
//    static const $UTF8_BOM                    = chr(0xEF) . chr(0xBB) . chr(0xBF);

    static function detect_utf_encoding($text) {
        $first2 = substr($text, 0, 2);
        $first3 = substr($text, 0, 3);
        $first4 = substr($text, 0, 3);
       
        if ($first3 == UTF8_BOM) return 'UTF-8';
        elseif ($first4 == UTF32_BIG_ENDIAN_BOM) return 'UTF-32BE';
        elseif ($first4 == UTF32_LITTLE_ENDIAN_BOM) return 'UTF-32LE';
        elseif ($first2 == UTF16_BIG_ENDIAN_BOM) return 'UTF-16BE';
        elseif ($first2 == UTF16_LITTLE_ENDIAN_BOM) return 'UTF-16LE';
    }
    
    static function getFileEncoding($str){
        $encoding=mb_detect_encoding($str);
        if(empty($encoding)){
            $encoding=self::detect_utf_encoding($str);
        }
        return $encoding;
    }
    
    //给定字符串，转换到指定的编码
    //@param $str 要转换编码的字符串
    //@param $to_encoding 转换到什么编码
    //@param $from_encoding 字符串的原始编码，不指定自动检测
    //@return 成功返回转化后的字符串 失败返回NULL
    static function ConvertEncoding($str, $to_encoding="UTF-8", $from_encoding = ''){
        $code = "ASCII,GBK,GB2312,UTF-8,EUC-CN,BIG-5,EUC-TW";
//        if($from_encoding == ''){
//            $from_encoding = mb_detect_encoding($content,$code);
//            if($from_encoding == "CP936")
//                $from_encoding = "GBK";
//        }
        return mb_convert_encoding($str,$to_encoding,$code);
        
    }

//以下的函数来自于Wordpress的Pinyin Permalinks (拼音链接)

/******************************************************************
 * Plugin Name: Pinyin Permalinks (拼音链接)
 *  Plugin URI: http://xiaole.happylive.org/wp_cha_jian/
 * Description: 为中文标题生成友好的拼音链接。 
 *              1 - 本插件兼容 Wordpress 英文友好 permalink；
 *              2 - 本插件仅对标题中的中文字符进行友好转换，字典范围为 GB2312 全码表约7000个汉字；
 *              4 - 非码表汉字会被忽略，如果标题里使用了特别的繁体汉字，可能需要手动为这些汉字添加拼音；
 *              5 - 新版本增加设置页面。
 *      Author: Xiaole Tao<xiaole.tao@gmail.com>
 *     Version: 2.1
 *  Author URI: http://xiaole.happylive.org
 ******************************************************************/


    /**
     * 将给定的字符串转换为拼音
     *
     * @param string $strTitle     要转化的字符串
     * @param string $PPS          转换为拼音后，汉字之间的分隔符
     * @param string $PPF          转换方式 默认为全拼转换
     * @param int    $PPL          需要转换的字符串长度，默认100，超过的部分自动剪裁掉
     * @return void
     */

     static public function getPinyin($strTitle, $PPS = '_', $PPF = 'fullword', $PPL = 100) {
        $dictPinyin = array('A'=>'啊阿吖嗄锕','Ai'=>'埃挨哎唉哀皑癌蔼矮艾碍爱隘捱嗳嫒瑷暧砹锿霭','An'=>'鞍氨安俺按暗岸胺案谙埯揞庵桉铵鹌黯','Ang'=>'肮昂盎','Ao'=>'凹敖熬翱袄傲奥懊澳坳拗嗷岙廒遨媪骜獒聱螯鏊鳌鏖','Ba'=>'芭捌扒叭吧笆八疤巴拔跋靶把坝霸罢爸茇菝岜灞钯粑鲅魃','Bai'=>'白柏百摆佰败拜稗捭掰','Ban'=>'斑班搬扳般颁板版扮拌伴瓣半办绊阪坂钣瘢癍舨','Bang'=>'邦帮梆榜膀绑棒磅蚌镑傍谤蒡浜','Bao'=>'苞胞包褒薄雹保堡饱宝抱报暴豹鲍爆曝勹葆孢煲鸨褓趵龅','Bei'=>'杯碑悲卑北辈背贝钡倍狈备惫焙被孛陂邶蓓呗悖碚鹎褙鐾鞴','Ben'=>'奔苯本笨畚坌锛','Beng'=>'崩绷甭泵蹦迸嘣甏','Bi'=>'逼鼻比鄙笔彼碧蓖蔽毕毙毖币庇痹闭敝弊必壁臂避陛匕俾荜荸萆薜吡哔狴庳愎滗濞弼妣婢嬖璧贲睥畀铋秕裨筚箅篦舭襞跸髀','Bian'=>'鞭边编贬扁便变卞辨辩辫遍匾弁苄忭汴缏煸砭碥窆褊蝙笾鳊','Biao'=>'标彪膘表婊骠飑飙飚镖镳瘭裱鳔','Bie'=>'鳖憋别瘪蹩','Bin'=>'彬斌濒滨宾摈傧豳缤玢殡膑镔髌鬓','Bing'=>'兵冰柄丙秉饼炳病并禀邴摒槟','Bo'=>'剥玻菠播拨钵波博勃搏铂箔伯帛舶脖膊渤泊驳卜亳啵饽檗擘礴钹鹁簸跛踣','Bu'=>'捕哺补埠不布步簿部怖卟逋瓿晡钚钸醭','Ca'=>'擦礤','Cai'=>'猜裁材才财睬踩采彩菜蔡','Can'=>'餐参蚕残惭惨灿孱骖璨粲黪','Cang'=>'苍舱仓沧藏伧','Cao'=>'操糙槽曹草嘈漕螬艚','Ce'=>'厕策侧册测恻','Cen'=>'岑涔','Ceng'=>'层蹭曾噌','Cha'=>'插叉茬茶查碴搽察岔差诧嚓猹馇汊姹杈槎檫锸镲衩','Chai'=>'拆柴豺侪钗瘥虿','Chan'=>'搀掺蝉馋谗缠铲产阐颤冁谄蒇廛忏潺澶羼婵骣觇禅蟾躔','Chang'=>'昌猖场尝常长偿肠厂敞畅唱倡伥鬯苌菖徜怅阊娼嫦昶氅鲳','Chao'=>'超抄钞朝嘲潮巢吵炒怊晁焯耖','Che'=>'车扯撤掣彻澈坼砗','Chen'=>'郴臣辰尘晨忱沉陈趁衬谌谶抻嗔宸琛榇碜龀','Cheng'=>'撑称城橙成呈乘程惩澄诚承逞骋秤丞埕枨柽塍瞠铖裎蛏酲','Chi'=>'吃痴持池迟弛驰耻齿侈尺赤翅斥炽傺墀茌叱哧啻嗤彳饬媸敕眵鸱瘛褫蚩螭笞篪豉踟魑','Chong'=>'充冲虫崇宠茺忡憧铳舂艟','Chou'=>'抽酬畴踌稠愁筹仇绸瞅丑臭俦帱惆瘳雠','Chu'=>'初出橱厨躇锄雏滁除楚础储矗搐触处畜亍刍怵憷绌杵楮樗褚蜍蹰黜','Chuai'=>'揣搋啜膪踹','Chuan'=>'川穿椽传船喘串舛遄氚钏舡','Chuang'=>'疮窗床闯创怆','Chui'=>'吹炊捶锤垂陲棰槌','Chun'=>'春椿醇唇淳纯蠢莼鹑蝽','Chuo'=>'戳绰辍踔龊','Ci'=>'疵茨磁雌辞慈瓷词此刺赐次茈祠鹚糍','Cong'=>'聪葱囱匆从丛苁淙骢琮璁枞','Cou'=>'凑楱辏腠','Cu'=>'粗醋簇促蔟徂猝殂蹙蹴','Cuan'=>'蹿篡窜汆撺爨镩','Cui'=>'摧崔催脆瘁粹淬翠萃啐悴璀榱毳','Cun'=>'村存寸忖皴','Cuo'=>'磋撮搓措挫错厝嵯脞锉矬痤鹾蹉','Da'=>'搭达答瘩打大耷哒嗒怛妲沓褡笪靼鞑','Dai'=>'呆歹傣戴带殆代贷袋待逮怠埭甙呔岱迨绐玳黛','Dan'=>'耽担丹单郸掸胆旦氮但惮淡诞弹蛋儋凼萏菪啖澹宕殚赕眈疸瘅聃箪','Dang'=>'当挡党荡档谠砀铛裆','Dao'=>'刀捣蹈倒岛祷导到稻悼道盗叨氘焘纛','De'=>'德得的锝','Deng'=>'蹬灯登等瞪凳邓噔嶝戥磴镫簦','Di'=>'堤低滴迪敌笛狄涤翟嫡抵底地蒂第帝弟递缔氐籴诋谛邸坻荻嘀娣柢棣觌祗砥碲睇镝羝骶','Dia'=>'嗲','Dian'=>'颠掂滇碘点典靛垫电佃甸店惦奠淀殿丶阽坫巅玷钿癜癫簟踮','Diao'=>'碉叼雕凋刁掉吊钓调铞貂鲷','Die'=>'跌爹碟蝶迭谍叠垤堞揲喋牒瓞耋鲽','Ding'=>'丁盯叮钉顶鼎锭定订仃啶玎腚碇町疔耵酊','Diu'=>'丢铥','Dong'=>'东冬董懂动栋侗恫冻洞垌咚岽峒氡胨胴硐鸫','Dou'=>'兜抖斗陡豆逗痘都蔸钭窦蚪篼','Du'=>'督毒犊独读堵睹赌杜镀肚度渡妒芏嘟渎椟牍蠹笃髑黩','Duan'=>'端短锻段断缎椴煅簖','Dui'=>'堆兑队对怼憝碓镦','Dun'=>'墩吨蹲敦顿钝盾遁沌炖砘礅盹趸','Duo'=>'掇哆多夺垛躲朵跺舵剁惰堕咄哚沲缍铎裰踱','E'=>'蛾峨鹅俄额讹娥恶厄扼遏鄂饿噩谔垩苊莪萼呃愕屙婀轭腭锇锷鹗颚鳄','Ei'=>'诶','En'=>'恩蒽摁嗯','Er'=>'而儿耳尔饵洱二贰迩珥铒鸸鲕','Fa'=>'发罚筏伐乏阀法珐垡砝','Fan'=>'藩帆番翻樊矾钒繁凡烦反返范贩犯饭泛蕃蘩幡梵燔畈蹯','Fang'=>'坊芳方肪房防妨仿访纺放邡枋钫舫鲂','Fei'=>'菲非啡飞肥匪诽吠肺废沸费芾狒悱淝妃绯榧腓斐扉砩镄痱蜚篚翡霏鲱','Fen'=>'芬酚吩氛分纷坟焚汾粉奋份忿愤粪偾瀵棼鲼鼢','Feng'=>'丰封枫蜂峰锋风疯烽逢冯缝讽奉凤俸酆葑唪沣砜','Fo'=>'佛','Fou'=>'否缶','Fu'=>'夫敷肤孵扶拂辐幅氟符伏俘服浮涪福袱弗甫抚辅俯釜斧脯腑府腐赴副覆赋复傅付阜父腹负富讣附妇缚咐匐凫郛芙苻茯莩菔拊呋呒幞怫滏艴孚驸绂绋桴赙祓黻黼罘稃馥蚨蜉蝠蝮麸趺跗鲋鳆','Ga'=>'噶嘎垓尬尕尜旮钆','Gai'=>'该改概钙盖溉丐陔戤赅','Gan'=>'干甘杆柑竿肝赶感秆敢赣坩苷尴擀泔淦澉绀橄旰矸疳酐','Gang'=>'冈刚钢缸肛纲岗港杠戆罡筻','Gao'=>'篙皋高膏羔糕搞镐稿告睾诰郜藁缟槔槁杲锆','Ge'=>'哥歌搁戈鸽胳疙割革葛格蛤阁隔铬个各咯鬲仡哿圪塥嗝纥搿膈硌镉袼虼舸骼','Gei'=>'给','Gen'=>'根跟亘茛哏艮','Geng'=>'耕更庚羹埂耿梗哽赓绠鲠','Gong'=>'工攻功恭龚供躬公宫弓巩汞拱贡共珙肱蚣觥','Gou'=>'钩勾沟苟狗垢构购够佝诟岣遘媾缑枸觏彀笱篝鞲','Gu'=>'辜菇咕箍估沽孤姑鼓古蛊骨谷股故顾固雇嘏诂菰崮汩梏轱牯牿臌毂瞽罟钴锢鸪痼蛄酤觚鲴','Gua'=>'刮瓜剐寡挂褂卦诖呱栝胍鸹','Guai'=>'乖拐怪','Guan'=>'棺关官冠观管馆罐惯灌贯倌莞掼涫盥鹳鳏','Guang'=>'光广逛咣犷桄胱','Gui'=>'瑰规圭硅归龟闺轨鬼诡癸桂柜跪贵刽匦刿庋宄妫炅晷皈簋鲑鳜','Gun'=>'辊滚棍衮绲磙鲧','Guo'=>'锅郭国果裹过馘埚掴呙帼崞猓椁虢聒蜾蝈','Ha'=>'哈铪','Hai'=>'骸孩海氦亥害骇嗨胲醢','Han'=>'酣憨邯韩含涵寒函喊罕翰撼捍旱憾悍焊汗汉邗菡撖犴阚瀚晗焓顸颔蚶鼾','Hang'=>'夯杭航沆绗颃','Hao'=>'壕嚎豪毫郝好耗号浩蒿薅嗥嚆濠灏昊皓颢蚝','He'=>'呵喝荷菏核禾和何合盒貉阂河涸赫褐鹤贺诃劾壑嗬阖曷盍颌蚵翮','Hei'=>'嘿黑','Hen'=>'痕很狠恨','Heng'=>'哼亨横衡恒蘅珩桁','Hong'=>'轰哄烘虹鸿洪宏弘红黉訇讧荭蕻薨闳泓','Hou'=>'喉侯猴吼厚候后堠後逅瘊篌糇鲎骺','Hu'=>'呼乎忽瑚壶葫胡蝴狐糊湖弧虎唬护互沪户冱唿囫岵猢怙惚浒滹琥槲轷觳烀煳戽扈祜瓠鹄鹕鹱笏醐斛鹘','Hua'=>'花哗华猾滑画划化话骅桦砉铧','Huai'=>'槐徊怀淮坏踝','Huan'=>'欢环桓还缓换患唤痪豢焕涣宦幻奂擐獾洹浣漶寰逭缳锾鲩鬟','Huang'=>'荒慌黄磺蝗簧皇凰惶煌晃幌恍谎隍徨湟潢遑璜肓癀蟥篁鳇','Hui'=>'灰挥辉徽恢蛔回毁悔慧卉惠晦贿秽会烩汇讳诲绘诙茴荟蕙咴喙隳洄彗缋桧晖恚虺蟪麾','Hun'=>'荤昏婚魂浑混诨馄阍溷珲','Huo'=>'豁活伙火获或惑霍货祸劐藿攉嚯夥钬锪镬耠蠖','Ji'=>'击圾基机畸稽积箕肌饥迹激讥鸡姬绩缉吉极棘辑籍集及急疾汲即嫉级挤几脊己蓟技冀季伎祭剂悸济寄寂计记既忌际妓继纪藉亟乩剞佶偈墼芨芰荠蒺蕺掎叽咭哜唧岌嵴洎屐骥畿玑楫殛戟戢赍觊犄齑矶羁嵇稷瘠虮笈笄暨跻跽霁鲚鲫髻麂','Jia'=>'嘉枷夹佳家加荚颊贾甲钾假稼价架驾嫁伽郏葭岬浃迦珈戛胛恝铗镓痂瘕蛱笳袈跏','Jian'=>'歼监坚尖笺间煎兼肩艰奸缄茧检柬碱硷拣捡简俭剪减荐槛鉴践贱见键箭件健舰剑饯渐溅涧建僭谏谫菅蒹搛湔蹇謇缣枧楗戋戬牮犍毽腱睑锏鹣裥笕翦踺鲣鞯','Jiang'=>'僵姜将浆江疆蒋桨奖讲匠酱降茳洚绛缰犟礓耩糨豇','Jiao'=>'蕉椒礁焦胶交郊浇骄娇嚼搅铰矫侥脚狡角饺缴绞剿教酵轿较叫窖佼僬艽茭挢噍徼姣敫皎鹪蛟醮跤鲛','Jie'=>'揭接皆秸街阶截劫节桔杰捷睫竭洁结解姐戒芥界借介疥诫届讦诘拮喈嗟婕孑桀碣疖颉蚧羯鲒骱','Jin'=>'巾筋斤金今津襟紧锦仅谨进靳晋禁近烬浸尽劲卺荩堇噤馑廑妗缙瑾槿赆觐衿矜','Jing'=>'荆兢茎睛晶鲸京惊精粳经井警景颈静境敬镜径痉靖竟竞净刭儆阱菁獍憬泾迳弪婧肼胫腈旌箐','Jiong'=>'炯窘迥扃','Jiu'=>'揪究纠玖韭久灸九酒厩救旧臼舅咎就疚僦啾阄柩桕鸠鹫赳鬏','Ju'=>'鞠拘狙疽居驹菊局咀矩举沮聚拒据巨具距踞锯俱句惧炬剧倨讵苣苴莒掬遽屦琚椐榘榉橘犋飓钜锔窭裾醵踽龃雎鞫','Juan'=>'捐鹃娟倦眷卷绢鄄狷涓桊蠲锩镌隽','Jue'=>'撅攫抉掘倔爵觉决诀绝厥劂谲矍蕨噘崛獗孓珏桷橛爝镢蹶觖','Jun'=>'均菌钧军君峻俊竣浚郡骏捃皲','Ka'=>'喀咖卡佧咔胩','Kai'=>'开揩楷凯慨剀垲蒈忾恺铠锎锴','Kan'=>'刊堪勘坎砍看侃莰戡龛瞰','Kang'=>'康慷糠扛抗亢炕伉闶钪','Kao'=>'考拷烤靠尻栲犒铐','Ke'=>'坷苛柯棵磕颗科壳咳可渴克刻客课嗑岢恪溘骒缂珂轲氪瞌钶锞稞疴窠颏蝌髁','Ken'=>'肯啃垦恳裉','Keng'=>'坑吭铿','Kong'=>'空恐孔控倥崆箜','Kou'=>'抠口扣寇芤蔻叩囗眍筘','Ku'=>'枯哭窟苦酷库裤刳堀喾绔骷','Kua'=>'夸垮挎跨胯侉','Kuai'=>'块筷侩快蒯郐哙狯浍脍','Kuan'=>'宽款髋','Kuang'=>'匡筐狂框矿眶旷况诓诳邝圹夼哐纩贶','Kui'=>'亏盔岿窥葵奎魁傀馈愧溃馗匮夔隗蒉揆喹喟悝愦逵暌睽聩蝰篑跬','Kun'=>'坤昆捆困悃阃琨锟醌鲲髡','Kuo'=>'括扩廓阔蛞','La'=>'垃拉喇蜡腊辣啦剌邋旯砬瘌','Lai'=>'莱来赖崃徕涞濑赉睐铼癞籁','Lan'=>'蓝婪栏拦篮阑兰澜谰揽览懒缆烂滥岚漤榄斓罱镧褴','Lang'=>'琅榔狼廊郎朗浪蒗啷阆稂螂','Lao'=>'捞劳牢老佬姥酪烙涝唠崂忉栳铑铹痨耢醪','Le'=>'勒乐了仂叻泐鳓','Lei'=>'雷镭蕾磊累儡垒擂肋类泪羸诔嘞嫘缧檑耒酹','Leng'=>'棱楞冷塄愣','Li'=>'厘梨犁黎篱狸离漓理李里鲤礼莉荔吏栗丽厉励砾历利傈例俐痢立粒沥隶力璃哩俪俚郦坜苈莅蓠藜呖唳喱猁溧澧逦娌嫠骊缡枥栎轹膦戾砺詈罹锂鹂疠疬蛎蜊蠡笠篥粝醴跞雳鲡鳢黧','Lian'=>'联莲连镰廉怜涟帘敛脸链恋炼练蔹奁潋濂琏楝殓臁裢裣蠊鲢','Liang'=>'俩粮凉梁粱良两辆量晾亮谅墚莨椋锒踉靓魉','Liao'=>'撩聊僚疗燎寥辽潦撂镣廖料蓼尥嘹獠寮缭钌鹩','Lie'=>'列裂烈劣猎冽埒捩咧洌趔躐鬣','Lin'=>'琳林磷霖临邻鳞淋凛赁吝拎蔺啉嶙廪懔遴檩辚瞵粼躏麟','Ling'=>'玲菱零龄铃伶羚凌灵陵岭领另令酃苓呤囹泠绫柃棂瓴聆蛉翎鲮','Liu'=>'溜琉榴硫馏留刘瘤流柳六浏遛骝绺旒熘锍镏鹨鎏','Long'=>'龙聋咙笼窿隆垄拢陇垅茏泷珑栊胧砻癃','Lou'=>'楼娄搂篓漏陋偻蒌喽嵝镂瘘耧蝼髅','Lu'=>'芦卢颅庐炉掳卤虏鲁麓碌露路赂鹿潞禄录陆戮垆撸噜泸渌漉逯璐栌橹轳辂辘氇胪镥鸬鹭簏舻鲈','Luan'=>'峦挛孪滦卵乱脔娈栾鸾銮','Lue'=>'掠略锊','Lun'=>'抡轮伦仑沦纶论囵','Luo'=>'萝螺罗逻锣箩骡裸落洛骆络倮蠃荦摞猡泺漯珞椤脶镙瘰雒','Lv'=>'驴吕铝侣旅履屡缕虑氯律滤绿捋闾榈膂稆褛','Ma'=>'妈麻玛码蚂马骂嘛吗唛犸杩蟆','Mai'=>'埋买麦卖迈脉劢荬霾','Man'=>'瞒馒蛮满蔓曼慢漫谩墁幔缦熳镘颟螨鳗鞔','Mang'=>'芒茫盲氓忙莽邙漭硭蟒','Mao'=>'猫茅锚毛矛铆卯茂冒帽貌贸袤茆峁泖瑁昴牦耄旄懋瞀蝥蟊髦','Me'=>'么麽','Mei'=>'玫枚梅酶霉煤没眉媒镁每美昧寐妹媚莓嵋猸浼湄楣镅鹛袂魅','Men'=>'门闷们扪焖懑钔','Meng'=>'萌蒙檬盟锰猛梦孟勐甍瞢懵朦礞虻蜢蠓艋艨','Mi'=>'眯醚靡糜迷谜弥米秘觅泌蜜密幂芈谧咪嘧猕汨宓弭脒祢敉縻麋','Mian'=>'棉眠绵冕免勉娩缅面沔渑湎腼眄','Miao'=>'苗描瞄藐秒渺庙妙喵邈缈杪淼眇鹋','Mie'=>'蔑灭乜咩蠛篾','Min'=>'民抿皿敏悯闽苠岷闵泯缗玟珉愍黾鳘','Ming'=>'明螟鸣铭名命冥茗溟暝瞑酩','Miu'=>'谬缪','Mo'=>'摸摹蘑模膜磨摩魔抹末莫墨默沫漠寞陌谟茉蓦馍嫫嬷殁镆秣瘼耱貊貘','Mou'=>'谋牟某侔哞眸蛑鍪','Mu'=>'拇牡亩姆母墓暮幕募慕木目睦牧穆仫坶苜沐毪钼','Na'=>'拿哪呐钠那娜纳讷捺肭镎衲','Nai'=>'氖乃奶耐奈鼐佴艿萘柰','Nan'=>'南男难喃囝囡楠腩蝻赧','Nang'=>'囊攮囔馕曩','Nao'=>'挠脑恼闹淖孬垴呶猱瑙硇铙蛲','Ne'=>'呢','Nei'=>'馁内','Nen'=>'嫩恁','Neng'=>'能','Ni'=>'妮霓倪泥尼拟你匿腻逆溺伲坭蘼猊怩昵旎睨铌鲵','Nian'=>'蔫拈年碾撵捻念廿埝辇黏鲇鲶','Niang'=>'娘酿','Niao'=>'鸟尿茑嬲脲袅','Nie'=>'捏聂孽啮镊镍涅陧蘖嗫颞臬蹑','Nin'=>'您','Ning'=>'柠狞凝宁拧泞佞咛甯聍','Niu'=>'牛扭钮纽狃忸妞','Nong'=>'脓浓农弄侬哝','Nou'=>'耨','Nu'=>'奴努怒弩胬孥驽','Nuan'=>'暖','Nue'=>'虐疟挪','Nuo'=>'懦糯诺傩搦喏锘','Nv'=>'女恧钕衄','O'=>'哦噢','Ou'=>'欧鸥殴藕呕偶沤讴怄瓯耦','Pa'=>'耙啪趴爬帕怕琶葩杷筢','Pai'=>'拍排牌徘湃派俳蒎哌','Pan'=>'攀潘盘磐盼畔判叛拚爿泮袢襻蟠蹒','Pang'=>'乓庞旁耪胖彷滂逄螃','Pao'=>'抛咆刨炮袍跑泡匏狍庖脬疱','Pei'=>'呸胚培裴赔陪配佩沛辔帔旆锫醅霈','Pen'=>'喷盆湓','Peng'=>'砰抨烹澎彭蓬棚硼篷膨朋鹏捧碰堋嘭怦蟛','Pi'=>'辟坯砒霹批披劈琵毗啤脾疲皮匹痞僻屁譬丕仳陴邳郫圮埤鼙芘擗噼庀淠媲纰枇甓罴铍癖疋蚍蜱貔','Pian'=>'篇偏片骗谝骈犏胼翩蹁','Piao'=>'飘漂瓢票剽嘌嫖缥殍瞟螵','Pie'=>'撇瞥丿苤氕','Pin'=>'拼频贫品聘姘嫔榀牝颦','Ping'=>'乒坪苹萍平凭瓶评屏俜娉枰鲆','Po'=>'坡泼颇婆破魄迫粕叵鄱珀钋钷皤笸','Pou'=>'剖裒掊','Pu'=>'扑铺仆莆葡菩蒲埔朴圃普浦谱瀑匍噗溥濮璞氆镤镨蹼','Qi'=>'期欺戚妻七凄漆柒沏其棋奇歧畦崎脐齐旗祈祁骑起岂乞企启契砌器气迄弃汽泣讫亓圻芑芪萁萋葺蕲嘁屺岐汔淇骐绮琪琦杞桤槭耆祺憩碛颀蛴蜞綦鳍麒','Qia'=>'掐恰洽葜袷髂','Qian'=>'牵扦钎铅千迁签仟谦乾黔钱钳前潜遣浅谴堑嵌欠歉倩佥阡芊芡掮岍悭慊骞搴褰缱椠肷愆钤虔箝','Qiang'=>'枪呛腔羌墙蔷强抢戕嫱樯戗炝锖锵镪襁蜣羟跄','Qiao'=>'橇锹敲悄桥瞧乔侨巧鞘撬翘峭俏窍劁诮谯荞峤愀憔缲樵硗跷鞒','Qie'=>'切茄且怯窃郄惬妾挈锲箧趄','Qin'=>'钦侵亲秦琴勤芹擒禽寝沁芩揿吣嗪噙溱檎锓螓衾','Qing'=>'青轻氢倾卿清擎晴氰情顷请庆苘圊檠磬蜻罄綮謦鲭黥','Qiong'=>'琼穷邛茕穹蛩筇跫銎','Qiu'=>'秋丘邱球求囚酋泅俅巯犰湫逑遒楸赇虬蚯蝤裘糗鳅鼽','Qu'=>'趋区蛆曲躯屈驱渠取娶龋趣去诎劬蕖蘧岖衢阒璩觑氍朐祛磲鸲癯蛐蠼麴瞿黢','Quan'=>'圈颧权醛泉全痊拳犬券劝诠荃犭悛绻辁畎铨蜷筌鬈','Que'=>'缺炔瘸却鹊榷确雀阕阙悫','Qun'=>'裙群逡麇','Ran'=>'然燃冉染苒蚺髯','Rang'=>'瓤壤攘嚷让禳穰','Rao'=>'饶扰绕荛娆桡','Re'=>'惹热','Ren'=>'壬仁人忍韧任认刃妊纫仞荏饪轫稔衽','Reng'=>'扔仍','Ri'=>'日','Rong'=>'戎茸蓉荣融熔溶容绒冗嵘狨榕肜蝾','Rou'=>'揉柔肉糅蹂鞣','Ru'=>'茹蠕儒孺如辱乳汝入褥蓐薷嚅洳溽濡缛铷襦颥','Ruan'=>'软阮朊','Rui'=>'蕊瑞锐芮蕤枘睿蚋','Run'=>'闰润','Ruo'=>'若弱偌箬','Sa'=>'撒洒萨卅挲脎飒','Sai'=>'腮鳃塞赛噻','San'=>'三叁伞散仨彡馓毵','Sang'=>'桑嗓丧搡磉颡','Sao'=>'搔骚扫嫂埽缫臊瘙鳋','Se'=>'瑟色涩啬铯穑','Sen'=>'森','Seng'=>'僧','Sha'=>'莎砂杀刹沙纱傻啥煞唼歃铩痧裟霎鲨','Shai'=>'筛晒酾','Shan'=>'珊苫杉山删煽衫闪陕擅赡膳善汕扇缮栅讪鄯芟潸姗嬗骟膻钐疝蟮舢跚鳝','Shang'=>'墒伤商赏晌上尚裳垧绱殇熵觞','Shao'=>'梢捎稍烧芍勺韶少哨邵绍劭潲杓蛸筲艄','She'=>'奢赊蛇舌舍赦摄射慑涉社设厍佘猞滠畲麝','Shen'=>'砷申呻伸身深娠绅神沈审婶甚肾慎渗什诜谂莘葚哂渖胂矧蜃糁','Sheng'=>'声生甥牲升绳省盛剩胜圣嵊晟眚笙','Shi'=>'匙师失狮施湿诗尸虱十石拾时食蚀实识史矢使屎驶始式示士世柿事拭誓逝势是嗜噬适仕侍释饰氏市恃室视试谥埘莳蓍弑轼贳炻礻铈舐筮豕鲥鲺','Shou'=>'收手首守寿授售受瘦兽狩绶艏','Shu'=>'蔬枢梳殊抒输叔舒淑疏书赎孰熟薯暑曙署蜀黍鼠属术述树束戍竖墅庶数漱恕丨倏塾菽摅沭澍姝纾毹腧殳秫','Shua'=>'刷耍唰','Shuai'=>'率摔衰甩帅蟀','Shuan'=>'栓拴闩涮','Shuang'=>'霜双爽孀','Shui'=>'谁水睡税','Shun'=>'吮瞬顺舜','Shuo'=>'说硕朔烁蒴搠妁槊铄','Si'=>'斯撕嘶思私司丝死肆寺嗣四伺似饲巳厮俟兕厶咝汜泗澌姒驷缌祀锶鸶耜蛳笥','Song'=>'松耸怂颂送宋讼诵凇菘崧嵩忪悚淞竦','Sou'=>'搜艘擞嗽叟薮嗖嗾馊溲飕瞍锼螋','Su'=>'苏酥俗素速粟僳塑溯宿诉肃夙谡蔌嗉愫涑簌觫稣','Suan'=>'酸蒜算狻','Sui'=>'虽隋随绥髓碎岁穗遂隧祟谇荽濉邃燧眭睢','Sun'=>'孙损笋荪狲飧榫隼','Suo'=>'蓑梭唆缩琐索锁所唢嗦嗍娑桫睃羧','Ta'=>'塌他它她塔獭挞蹋踏闼溻遢榻铊趿鳎','Tai'=>'胎苔抬台泰酞太态汰邰薹骀肽炱钛跆鲐','Tan'=>'坍摊贪瘫滩坛檀痰潭谭谈坦毯袒碳探叹炭郯昙忐钽锬覃','Tang'=>'汤塘搪堂棠膛唐糖倘躺淌趟烫傥帑惝溏瑭樘铴镗耥螗螳羰醣','Tao'=>'掏涛滔绦萄桃逃淘陶讨套鼗啕洮韬饕','Te'=>'特忒忑慝铽','Teng'=>'藤腾疼誊滕','Ti'=>'梯剔踢锑提题蹄啼体替嚏惕涕剃屉倜悌逖绨缇鹈醍','Tian'=>'天添填田甜恬舔腆掭忝阗殄畋','Tiao'=>'挑条迢眺跳佻苕祧窕蜩笤粜龆鲦髫','Tie'=>'贴铁帖萜餮','Ting'=>'厅听烃汀廷停亭庭挺艇莛葶婷梃铤蜓霆','Tong'=>'通桐酮瞳同铜彤童桶捅筒统痛佟仝茼嗵恸潼砼','Tou'=>'偷投头透骰','Tu'=>'凸秃突图徒途涂屠土吐兔堍荼菟钍酴','Tuan'=>'湍团抟彖疃','Tui'=>'推颓腿蜕褪退煺','Tun'=>'囤吞屯臀氽饨暾豚','Tuo'=>'拖托脱鸵陀驮驼椭妥拓唾佗坨庹沱柝柁橐砣箨酡跎鼍','Wa'=>'挖哇蛙洼娃瓦袜佤娲腽','Wai'=>'歪外崴','Wan'=>'豌弯湾玩顽丸烷完碗挽晚皖惋宛婉万腕剜芄菀纨绾琬脘畹蜿','Wang'=>'汪王亡枉网往旺望忘妄罔惘辋魍','Wei'=>'威巍微危韦违桅围唯惟为潍维苇萎委伟伪尾纬未蔚味畏胃喂魏位渭谓尉慰卫偎诿隈圩葳薇帏帷嵬猥猬闱沩洧涠逶娓玮韪軎炜煨痿艉鲔','Wen'=>'瘟温蚊文闻纹吻稳紊问刎夂阌汶璺攵雯','Weng'=>'嗡翁瓮蓊蕹','Wo'=>'挝蜗涡窝我斡卧握沃倭莴喔幄渥肟硪龌','Wu'=>'巫呜钨乌污诬屋无芜梧吾吴毋武五捂午舞伍侮坞戊雾晤物勿务悟误兀仵阢邬圬芴唔庑怃忤寤迕妩婺骛杌牾焐鹉鹜痦蜈鋈鼯','Xi'=>'栖昔熙析西硒矽晰嘻吸锡牺稀息希悉膝夕惜熄烯溪汐犀檄袭席习媳喜铣洗系隙戏细僖兮隰郗茜菥葸蓰奚唏徙饩阋浠淅屣嬉玺樨曦觋欷歙熹禊禧皙穸裼蜥螅蟋舄舾羲粞翕醯蹊鼷','Xia'=>'瞎虾匣霞辖暇峡侠狭下厦夏吓呷狎遐瑕柙硖罅黠','Xian'=>'掀锨先仙鲜纤咸贤衔舷闲涎弦嫌显险现献县腺馅羡宪陷限线冼苋莶藓岘猃暹娴氙燹祆鹇痫蚬筅籼酰跣跹霰','Xiang'=>'相厢镶香箱襄湘乡翔祥详想响享项巷橡像向象芗葙饷庠骧缃蟓鲞飨','Xiao'=>'萧硝霄削哮嚣销消宵淆晓小孝校肖啸笑效哓崤潇逍骁绡枭枵筱箫魈','Xie'=>'楔些歇蝎鞋协挟携邪斜胁谐写械卸蟹懈泄泻谢屑偕亵勰燮薤撷獬廨渫瀣邂绁缬榭榍蹀躞','Xin'=>'薪芯锌欣辛新忻心信衅囟馨昕歆镡鑫','Xing'=>'星腥猩惺兴刑型形邢行醒幸杏性姓陉荇荥擤饧悻硎','Xiong'=>'兄凶胸匈汹雄熊芎','Xiu'=>'休修羞朽嗅锈秀袖绣咻岫馐庥溴鸺貅髹','Xu'=>'墟戌需虚嘘须徐许蓄酗叙旭序恤絮婿绪续吁诩勖蓿洫溆顼栩煦盱胥糈醑','Xuan'=>'轩喧宣悬旋玄选癣眩绚儇谖萱揎泫渲漩璇楦暄炫煊碹铉镟痃','Xue'=>'靴薛学穴雪血谑噱泶踅鳕','Xun'=>'勋熏循旬询寻驯巡殉汛训讯逊迅巽郇埙荀荨蕈薰峋徇獯恂洵浔曛醺鲟','Ya'=>'压押鸦鸭呀丫芽牙蚜崖衙涯雅哑亚讶伢垭揠岈迓娅琊桠氩砑睚痖','Yan'=>'焉咽阉烟淹盐严研蜒岩延言颜阎炎沿奄掩眼衍演艳堰燕厌砚雁唁彦焰宴谚验厣赝剡俨偃兖谳郾鄢埏菸崦恹闫阏湮滟妍嫣琰檐晏胭腌焱罨筵酽趼魇餍鼹','Yang'=>'殃央鸯秧杨扬佯疡羊洋阳氧仰痒养样漾徉怏泱炀烊恙蛘鞅','Yao'=>'邀腰妖瑶摇尧遥窑谣姚咬舀药要耀钥夭爻吆崾徭幺珧杳轺曜肴铫鹞窈繇鳐','Ye'=>'椰噎耶爷野冶也页掖业叶曳腋夜液靥谒邺揶晔烨铘','Yi'=>'一壹医揖铱依伊衣颐夷遗移仪胰疑沂宜姨彝椅蚁倚已乙矣以艺抑易邑屹亿役臆逸肄疫亦裔意毅忆义益溢诣议谊译异翼翌绎刈劓佚佾诒圯埸懿苡荑薏弈奕挹弋呓咦咿嗌噫峄嶷猗饴怿怡悒漪迤驿缢殪轶贻欹旖熠眙钇镒镱痍瘗癔翊蜴舣羿翳酏黟','Yin'=>'茵荫因殷音阴姻吟银淫寅饮尹引隐印胤鄞垠堙茚吲喑狺夤洇氤铟瘾窨蚓霪龈','Ying'=>'英樱婴鹰应缨莹萤营荧蝇迎赢盈影颖硬映嬴郢茔莺萦蓥撄嘤膺滢潆瀛瑛璎楹媵鹦瘿颍罂','Yo'=>'哟唷','Yong'=>'拥佣臃痈庸雍踊蛹咏泳涌永恿勇用俑壅墉喁慵邕镛甬鳙饔','You'=>'幽优悠忧尤由邮铀犹油游酉有友右佑釉诱又幼卣攸侑莠莜莸尢呦囿宥柚猷牖铕疣蚰蚴蝣鱿黝鼬','Yu'=>'迂淤于盂榆虞愚舆余俞逾鱼愉渝渔隅予娱雨与屿禹宇语羽玉域芋郁遇喻峪御愈欲狱育誉浴寓裕预豫驭禺毓伛俣谀谕萸蓣揄圄圉嵛狳饫馀庾阈鬻妪妤纡瑜昱觎腴欤於煜燠聿钰鹆鹬瘐瘀窬窳蜮蝓竽臾舁雩龉','Yuan'=>'鸳渊冤元垣袁原援辕园员圆猿源缘远苑愿怨院垸塬芫掾圜沅媛瑗橼爰眢鸢螈箢鼋','Yue'=>'曰约越跃岳粤月悦阅龠哕瀹樾刖钺','Yun'=>'耘云郧匀陨允运蕴酝晕韵孕郓芸狁恽愠纭韫殒昀氲熨筠','Za'=>'匝砸杂咋拶咂','Zai'=>'栽哉灾宰载再在崽甾','Zan'=>'咱攒暂赞瓒昝簪糌趱錾','Zang'=>'赃脏葬奘驵臧','Zao'=>'遭糟凿藻枣早澡蚤躁噪造皂灶燥唣','Ze'=>'责择则泽仄赜啧帻迮昃笮箦舴','Zei'=>'贼','Zen'=>'怎谮','Zeng'=>'增憎赠缯甑罾锃','Zha'=>'扎喳渣札轧铡闸眨榨乍炸诈柞揸吒咤哳楂砟痄蚱齄','Zhai'=>'摘斋宅窄债寨砦瘵','Zhan'=>'瞻毡詹粘沾盏斩辗崭展蘸栈占战站湛绽谵搌旃','Zhang'=>'樟章彰漳张掌涨杖丈帐账仗胀瘴障仉鄣幛嶂獐嫜璋蟑','Zhao'=>'招昭找沼赵照罩兆肇召诏棹钊笊','Zhe'=>'遮折哲蛰辙者锗蔗这浙着乇谪摺柘辄磔鹧褶蜇螫赭','Zhen'=>'珍斟真甄砧臻贞针侦枕疹诊震振镇阵帧圳蓁浈缜桢椹榛轸赈胗朕祯畛稹鸩箴','Zheng'=>'蒸挣睁征狰争怔整拯正政症郑证诤峥徵钲铮筝','Zhi'=>'芝枝支吱蜘知肢脂汁之织职直植殖执值侄址指止趾只旨纸志挚掷至致置帜峙制智秩稚质炙痔滞治窒卮陟郅埴芷摭帙忮彘咫骘栉枳栀桎轵轾贽胝膣祉黹雉鸷痣蛭絷酯跖踬踯豸觯','Zhong'=>'中盅忠钟衷终种肿重仲众冢锺螽舯踵','Zhou'=>'舟周州洲诌粥轴肘帚咒皱宙昼骤荮啁妯纣绉胄碡籀酎','Zhu'=>'珠株蛛朱猪诸诛逐竹烛煮拄瞩嘱主著柱助蛀贮铸筑住注祝驻伫侏邾苎茱洙渚潴杼槠橥炷铢疰瘃竺箸舳翥躅麈','Zhua'=>'抓爪','Zhuai'=>'拽','Zhuan'=>'专砖转撰赚篆啭馔颛','Zhuang'=>'幢桩庄装妆撞壮状僮','Zhui'=>'椎锥追赘坠缀萑惴骓缒隹','Zhun'=>'谆准肫窀','Zhuo'=>'捉拙卓桌琢茁酌啄灼浊倬诼擢浞涿濯禚斫镯','Zi'=>'兹咨资姿滋淄孜紫仔籽滓子自渍字谘呲嵫姊孳缁梓辎赀恣眦锱秭耔笫粢趑訾龇鲻髭','Zong'=>'鬃棕踪宗综总纵偬腙粽','Zou'=>'邹走奏揍诹陬鄹驺鲰','Zu'=>'租足卒族祖诅阻组俎菹镞','Zuan'=>'钻纂攥缵躜','Zui'=>'嘴醉最罪蕞觜','Zun'=>'尊遵撙樽鳟','Zuo'=>'昨左佐做作坐座阼唑嘬怍胙祚酢'); 
		
		$strRet = '';


        //判断当前编码方式
        $curr_charset = __get_config("Common.CharSet");
        if( $curr_charset != "UTF-8") {
            $strTitle = iconv($curr_charset, "UTF-8", $strTitle);
        }
        if($PPL>0) { $strTitle=substr($strTitle,0,$PPL); }
        for ($i = 0; $i < strlen($strTitle); $i++) {
            //取一个字节
            $byte1st = ord(substr($strTitle, $i, 1));
            //如果在 11100000-11101111 范围间的，说明是一个UTF-8的中文字
            if ($byte1st >= 224 && $byte1st <= 239) {
                //抓取整个汉字，UTF-8的汉字是3字节的
                $fullChar = substr($strTitle, $i, 3); $i+=2;
                //在字典里查找拼音，找不到的汉字会忽略
                foreach ($dictPinyin as $pinyin=>$val) {
                    if (strpos($val, $fullChar) !== false) {
                        if ($PPF=="fullword") {
                            $strRet .= $PPS.$pinyin.$PPS;
                        } else {
                            $strRet .= $PPS.substr($pinyin,0,1).$PPS;
                        }
                        break;
                    };
                }
            } else {
                //非中文的话，把不认识的符号都转成空格
                $strRet .= preg_replace("/[^A-Za-z0-9\-]/", $PPS, chr($byte1st));
            }
        }
        if ($PPS!="") {
            $strRet=trim(preg_replace("/".$PPS."+/", $PPS, $strRet), $PPS);
        }
        return $strRet;
    }


//以下内容来自ThinkPHP
    
    /**
     +----------------------------------------------------------
     * 生成UUID 单机使用
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
     static public function uuid() {
        $charid = md5(uniqid(mt_rand(), true));
        $hyphen = chr(45);// "-"
        $uuid = chr(123)// "{"
               .substr($charid, 0, 8).$hyphen
               .substr($charid, 8, 4).$hyphen
               .substr($charid,12, 4).$hyphen
               .substr($charid,16, 4).$hyphen
               .substr($charid,20,12)
               .chr(125);// "}"
        return $uuid;
   }

    /**
     +----------------------------------------------------------
     * 生成Guid主键
     +----------------------------------------------------------
     * @return Boolean
     +----------------------------------------------------------
     */
    static public function keyGen() {
        return str_replace('-','',substr(StringFuncs::uuid(),1,-1));
    }

    /**
     +----------------------------------------------------------
     * 检查字符串是否是UTF8编码
     +----------------------------------------------------------
     * @param string $string 字符串
     +----------------------------------------------------------
     * @return Boolean
     +----------------------------------------------------------
     */
    static public function isUtf8($str) {
        $c=0; $b=0;
        $bits=0;
        $len=strlen($str);
        for($i=0; $i<$len; $i++){
            $c=ord($str[$i]);
            if($c > 128){
                if(($c >= 254)) return false;
                elseif($c >= 252) $bits=6;
                elseif($c >= 248) $bits=5;
                elseif($c >= 240) $bits=4;
                elseif($c >= 224) $bits=3;
                elseif($c >= 192) $bits=2;
                else return false;
                if(($i+$bits) > $len) return false;
                while($bits > 1){
                    $i++;
                    $b=ord($str[$i]);
                    if($b < 128 || $b > 191) return false;
                    $bits--;
                }
            }
        }
        return true;
    }

    /**
     +----------------------------------------------------------
     * 字符串截取，支持中文和其他编码
     +----------------------------------------------------------
     * @static
     * @access public
     +----------------------------------------------------------
     * @param string $str 需要转换的字符串
     * @param string $start 开始位置
     * @param string $length 截取长度
     * @param string $charset 编码格式
     * @param string $suffix 截断显示字符
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
	//fenghao edit this 
	//2012-05-04
	//odl: $suffix = true
    static public function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=false) {
        if(function_exists("mb_substr"))
            $slice = mb_substr($str, $start, $length, $charset);
        elseif(function_exists('iconv_substr')) {
            $slice = iconv_substr($str,$start,$length,$charset);
        }else{
            $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
            $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
            $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
            $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
            preg_match_all($re[$charset], $str, $match);
            $slice = join("",array_slice($match[0], $start, $length));
        }
        return $suffix ? $slice.'...' : $slice;
    }

    /**
     +----------------------------------------------------------
     * 产生随机字串，可用来自动生成密码
     * 默认长度6位 字母和数字混合 支持中文
     +----------------------------------------------------------
     * @param string $len 长度
     * @param string $type 字串类型
     * 0 字母 1 数字 其它 混合
     * @param string $addChars 额外字符
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
    static public function randString($len=6,$type='',$addChars='') {
        $str ='';
        switch($type) {
            case 0:
                $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars;
                break;
            case 1:
                $chars= str_repeat('0123456789',3);
                break;
            case 2:
                $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars;
                break;
            case 3:
                $chars='abcdefghijklmnopqrstuvwxyz'.$addChars;
                break;
            case 4:
                $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借".$addChars;
                break;
            default :
                // 默认去掉了容易混淆的字符oOLl和数字01，要添加请使用addChars参数
                $chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars;
                break;
        }
        if($len>10 ) {//位数过长重复字符串一定次数
            $chars= $type==1? str_repeat($chars,$len) : str_repeat($chars,5);
        }
        if($type!=4) {
            $chars   =   str_shuffle($chars);
            $str     =   substr($chars,0,$len);
        }else{
            // 中文随机字
            for($i=0;$i<$len;$i++){
              $str.= self::msubstr($chars, floor(mt_rand(0,mb_strlen($chars,'utf-8')-1)),1);
            }
        }
        return $str;
    }

    /**
     +----------------------------------------------------------
     * 生成一定数量的随机数，并且不重复
     +----------------------------------------------------------
     * @param integer $number 数量
     * @param string $len 长度
     * @param string $type 字串类型
     * 0 字母 1 数字 其它 混合
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
    static public function buildCountRand ($number,$length=4,$mode=1) {
            if($mode==1 && $length<strlen($number) ) {
                //不足以生成一定数量的不重复数字
                return false;
            }
            $rand   =  array();
            for($i=0; $i<$number; $i++) {
                $rand[] =   self::randString($length,$mode);
            }
            $unqiue = array_unique($rand);
            if(count($unqiue)==count($rand)) {
                return $rand;
            }
            $count   = count($rand)-count($unqiue);
            for($i=0; $i<$count*3; $i++) {
                $rand[] =   self::randString($length,$mode);
            }
            $rand = array_slice(array_unique ($rand),0,$number);
            return $rand;
    }

    /**
     +----------------------------------------------------------
     *  带格式生成随机字符 支持批量生成
     *  但可能存在重复
     +----------------------------------------------------------
     * @param string $format 字符格式
     *     # 表示数字 * 表示字母和数字 $ 表示字母
     * @param integer $number 生成数量
     +----------------------------------------------------------
     * @return string | array
     +----------------------------------------------------------
     */
    static public function buildFormatRand($format,$number=1) {
        $str  =  array();
        $length =  strlen($format);
        for($j=0; $j<$number; $j++) {
            $strtemp   = '';
            for($i=0; $i<$length; $i++) {
                $char = substr($format,$i,1);
                switch($char){
                    case "*"://字母和数字混合
                        $strtemp   .= String::randString(1);
                        break;
                    case "#"://数字
                        $strtemp  .= String::randString(1,1);
                        break;
                    case "$"://大写字母
                        $strtemp .=  String::randString(1,2);
                        break;
                    default://其他格式均不转换
                        $strtemp .=   $char;
                        break;
               }
            }
            $str[] = $strtemp;
        }

        return $number==1? $strtemp : $str ;
    }

    /**
     +----------------------------------------------------------
     * 获取一定范围内的随机数字 位数不足补零
     +----------------------------------------------------------
     * @param integer $min 最小值
     * @param integer $max 最大值
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
    static public function randNumber ($min, $max) {
        return sprintf("%0".strlen($max)."d", mt_rand($min,$max));
    }

    // 自动转换字符集 支持数组转换
    static public function autoCharset($string, $from='gbk', $to='utf-8') {
        $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
        $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
        if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) {
            //如果编码相同或者非字符串标量则不转换
            return $string;
        }
        if (is_string($string)) {
            if (function_exists('mb_convert_encoding')) {
                return mb_convert_encoding($string, $to, $from);
            } elseif (function_exists('iconv')) {
                return iconv($from, $to, $string);
            } else {
                return $string;
            }
        } elseif (is_array($string)) {
            foreach ($string as $key => $val) {
                $_key = self::autoCharset($key, $from, $to);
                $string[$_key] = self::autoCharset($val, $from, $to);
                if ($key != $_key)
                    unset($string[$key]);
            }
            return $string;
        }
        else {
            return $string;
        }
    }

}

?>